package com.fili.core;

import java.io.IOException;
import java.io.PrintStream;
import java.io.FileNotFoundException;
import java.util.Date;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Oct 29, 2006
 * Time: 10:35:19 AM
 */
public class Log
{
    private static PrintStream debugStream = null;

    public static void writeLog(Object obj)
    {
        if (debugStream == null)
        {
            debugStream = System.err;
/*            try
            {
                debugStream = new PrintStream("./log.txt");
            }
            catch (FileNotFoundException e)
            {
                debugStream = System.err;
                e.printStackTrace();
            }*/
        }

        try
        {
            debugStream.write((new Date()).toString().getBytes());
            debugStream.write("\n".getBytes());
            if (obj instanceof Exception)
                ((Exception) obj).printStackTrace(debugStream);
            else
                debugStream.write(obj.toString().getBytes());
            debugStream.write("\n".getBytes());
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
